/*
Copyright (C) 2013, 2014 Bengt Martensson.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/.
*/

package org.harctoolbox.guicomponents;

public class HexCalculator extends HarcPanel {
    private static final long serialVersionUID = 1L;

    private static final String versionString = "0.3.0";
    private static final String helpText =
            "This pane computes, for a number given in first row either as decimal or hexadecimal\n"
            + "its (one-) complement (in 8, 16, or 32 bits), its \"reverse\" (java.lang.Integer.reverse():\n"
            + "the value obtained by reversing the order of the bits in the two's complement binary\n"
            + "representation of the specified int value)."
            ;

    private static final String aboutText =
            "HexCalculator version " + versionString + ".\n"
            + "Copyright 2012, 2013, 2014 by Bengt Martensson.\n\n"
            + "License: GPL3.\n\n"
            + "Project home page: http://www.harctoolbox.org";

    private static final String invalidString = "****";

    /**
     * Creates new form HexCalculator.
     */
    public HexCalculator() {
        initComponents();
    }

    @Override
    public String getHelpMessage() {
        return helpText;
    }

    @Override
    public String getAboutMessage() {
        return aboutText;
    }

    @Override
    public String getProgName() {
        return "HexCalculator";
    }

    @Override
    public String getIconPath() {
        return "/icons/Crystal-Clear/22x22/apps/calc.png";
    }

    private String hexFormat(int noBytes, long x) {
        String hexFormat = "%0" + 2*noBytes + "X";
        return String.format(hexFormat, x);
    }

    private void updateHexcalc(long in, int noBytes) {
        long comp = (1L << (8*noBytes)) - 1;
        long rev = (Long.reverse(in) >> (64 - 8*noBytes)) & comp;
        complementDecimalTextField.setText(Long.toString(comp - in));
        complementHexTextField.setText(hexFormat(noBytes, comp - in));
        reverseDecimalTextField.setText(Long.toString(rev));
        reverseHexTextField.setText(hexFormat(noBytes , rev));
        reverseComplementHexTextField.setText(hexFormat(noBytes, comp-rev));
        reverseComplementDecimalTextField.setText(Long.toString(comp-rev));
        statusLine.setStatus(null);
    }

    private void hexcalcSillyNumber(String str) {
        // Prevent multiple invocations of error()
        if (complementDecimalTextField.getText().equalsIgnoreCase(invalidString))
            return;

        complementDecimalTextField.setText(invalidString);
        complementHexTextField.setText(invalidString);
        reverseDecimalTextField.setText(invalidString);
        reverseHexTextField.setText(invalidString);
        reverseComplementDecimalTextField.setText(invalidString);
        reverseComplementHexTextField.setText(invalidString);
        statusLine.setStatus(str);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        copyPastePopupMenu = new org.harctoolbox.guicomponents.CopyPastePopupMenu(true);
        copyPopupMenu = new org.harctoolbox.guicomponents.CopyPastePopupMenu();
        hexTextField = new javax.swing.JTextField();
        reverseDecimalTextField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        complementDecimalTextField = new javax.swing.JTextField();
        reverseComplementHexTextField = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        reverseHexTextField = new javax.swing.JTextField();
        reverseComplementDecimalTextField = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        decimalTextField = new javax.swing.JTextField();
        complementHexTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        statusLine = new org.harctoolbox.guicomponents.StatusLine();

        hexTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        hexTextField.setText("00");
        hexTextField.setToolTipText("Enter hexadecimal number here, then press return.");
        hexTextField.setMinimumSize(new java.awt.Dimension(100, 27));
        hexTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        hexTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                hexTextFieldgenericCopyPasteMenu(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                hexTextFieldgenericCopyPasteMenu1(evt);
            }
        });
        hexTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hexTextFieldActionPerformed(evt);
            }
        });
        hexTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                hexTextFieldFocusLost(evt);
            }
        });

        reverseDecimalTextField.setEditable(false);
        reverseDecimalTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        reverseDecimalTextField.setText("0");
        reverseDecimalTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        reverseDecimalTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                reverseDecimalTextFieldgenericCopyMenu(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                reverseDecimalTextFieldgenericCopyMenu1(evt);
            }
        });

        jLabel8.setText("Complement");
        jLabel8.setToolTipText("(One) complement: all bits inverted.");

        complementDecimalTextField.setEditable(false);
        complementDecimalTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        complementDecimalTextField.setText("255");
        complementDecimalTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        complementDecimalTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                complementDecimalTextFieldgenericCopyMenu(evt);
            }
        });

        reverseComplementHexTextField.setEditable(false);
        reverseComplementHexTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        reverseComplementHexTextField.setText("FF");
        reverseComplementHexTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        reverseComplementHexTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                reverseComplementHexTextFieldgenericCopyMenu(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                reverseComplementHexTextFieldgenericCopyMenu1(evt);
            }
        });

        jLabel14.setText("LSB");
        jLabel14.setToolTipText("Result with the reverse bit order (LSB: least significant bit (first)).");

        jLabel6.setText("Decimal");

        reverseHexTextField.setEditable(false);
        reverseHexTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        reverseHexTextField.setText("00");
        reverseHexTextField.setMinimumSize(new java.awt.Dimension(100, 27));
        reverseHexTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        reverseHexTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                reverseHexTextFieldgenericCopyMenu(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                reverseHexTextFieldgenericCopyMenu1(evt);
            }
        });

        reverseComplementDecimalTextField.setEditable(false);
        reverseComplementDecimalTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        reverseComplementDecimalTextField.setText("255");
        reverseComplementDecimalTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        reverseComplementDecimalTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                reverseComplementDecimalTextFieldgenericCopyMenu(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                reverseComplementDecimalTextFieldgenericCopyMenu1(evt);
            }
        });

        jLabel15.setText("LSB-Compl.");
        jLabel15.setToolTipText("All bits inverted, in the reverse order.");

        jLabel9.setText("Input");

        decimalTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        decimalTextField.setText("0");
        decimalTextField.setToolTipText("Enter decimal number here, then press return.");
        decimalTextField.setMinimumSize(new java.awt.Dimension(100, 27));
        decimalTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        decimalTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                decimalTextFieldgenericCopyPasteMenu(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                decimalTextFieldgenericCopyPasteMenu1(evt);
            }
        });
        decimalTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decimalTextFieldActionPerformed(evt);
            }
        });
        decimalTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                decimalTextFieldFocusLost(evt);
            }
        });

        complementHexTextField.setEditable(false);
        complementHexTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        complementHexTextField.setText("FF");
        complementHexTextField.setMinimumSize(new java.awt.Dimension(100, 27));
        complementHexTextField.setPreferredSize(new java.awt.Dimension(100, 27));
        complementHexTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                complementHexTextFieldgenericCopyMenu(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                complementHexTextFieldgenericCopyMenu1(evt);
            }
        });

        jLabel7.setText("Hex");

        statusLine.setText("statusLine");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(reverseComplementDecimalTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(reverseDecimalTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(complementDecimalTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(decimalTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(hexTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(complementHexTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(reverseHexTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(reverseComplementHexTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(statusLine, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(decimalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hexTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(complementDecimalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(complementHexTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(reverseDecimalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(reverseHexTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(reverseComplementDecimalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(reverseComplementHexTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusLine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void hexTextFieldgenericCopyPasteMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hexTextFieldgenericCopyPasteMenu
        if (evt.isPopupTrigger())
        copyPastePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_hexTextFieldgenericCopyPasteMenu

    private void hexTextFieldgenericCopyPasteMenu1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hexTextFieldgenericCopyPasteMenu1
        if (evt.isPopupTrigger())
        copyPastePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_hexTextFieldgenericCopyPasteMenu1

    private void hexTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hexTextFieldActionPerformed
        try {
            long in = Long.parseLong(hexTextField.getText(), 16);
            if (in > 0xFFFFFFFFL) {
                decimalTextField.setText(invalidString);
                hexcalcSillyNumber("Number too large");
                return;
            }
            int noBytes = hexTextField.getText().length() <= 2 ? 1
                : hexTextField.getText().length() <= 4 ? 2 : 4;
            hexTextField.setText(hexFormat(noBytes, in));
            decimalTextField.setText(Long.toString(in));
            updateHexcalc(in, noBytes);
        } catch (NumberFormatException e) {
            decimalTextField.setText("*");
            hexcalcSillyNumber("Parse error: " + e.getMessage());
        }
    }//GEN-LAST:event_hexTextFieldActionPerformed

    private void hexTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_hexTextFieldFocusLost
        hexTextFieldActionPerformed(null);
    }//GEN-LAST:event_hexTextFieldFocusLost

    private void reverseDecimalTextFieldgenericCopyMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseDecimalTextFieldgenericCopyMenu
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseDecimalTextFieldgenericCopyMenu

    private void reverseDecimalTextFieldgenericCopyMenu1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseDecimalTextFieldgenericCopyMenu1
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseDecimalTextFieldgenericCopyMenu1

    private void complementDecimalTextFieldgenericCopyMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_complementDecimalTextFieldgenericCopyMenu
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_complementDecimalTextFieldgenericCopyMenu

    private void reverseComplementHexTextFieldgenericCopyMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseComplementHexTextFieldgenericCopyMenu
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseComplementHexTextFieldgenericCopyMenu

    private void reverseComplementHexTextFieldgenericCopyMenu1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseComplementHexTextFieldgenericCopyMenu1
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseComplementHexTextFieldgenericCopyMenu1

    private void reverseHexTextFieldgenericCopyMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseHexTextFieldgenericCopyMenu
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseHexTextFieldgenericCopyMenu

    private void reverseHexTextFieldgenericCopyMenu1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseHexTextFieldgenericCopyMenu1
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseHexTextFieldgenericCopyMenu1

    private void reverseComplementDecimalTextFieldgenericCopyMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseComplementDecimalTextFieldgenericCopyMenu
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseComplementDecimalTextFieldgenericCopyMenu

    private void reverseComplementDecimalTextFieldgenericCopyMenu1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reverseComplementDecimalTextFieldgenericCopyMenu1
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_reverseComplementDecimalTextFieldgenericCopyMenu1

    private void decimalTextFieldgenericCopyPasteMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_decimalTextFieldgenericCopyPasteMenu
        if (evt.isPopupTrigger())
        copyPastePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_decimalTextFieldgenericCopyPasteMenu

    private void decimalTextFieldgenericCopyPasteMenu1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_decimalTextFieldgenericCopyPasteMenu1
        if (evt.isPopupTrigger())
        copyPastePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_decimalTextFieldgenericCopyPasteMenu1

    private void decimalTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decimalTextFieldActionPerformed
        try {
            long in = Long.parseLong(decimalTextField.getText());
            if (in > 0xFFFFFFFFL) {
                hexTextField.setText(invalidString);
                hexcalcSillyNumber("Number too large");
                return;
            }
            int noBytes = (in < 256 && decimalTextField.getText().length() <= 3) ? 1
                    : (in < 65536 && decimalTextField.getText().length() <= 5) ? 2
                    : 4;
            hexTextField.setText(hexFormat(noBytes, in));
            updateHexcalc(in, noBytes);
        } catch (NumberFormatException e) {
            hexTextField.setText("*");
            hexcalcSillyNumber("Parse error: " + e.getMessage());
        }
    }//GEN-LAST:event_decimalTextFieldActionPerformed

    private void decimalTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_decimalTextFieldFocusLost
        decimalTextFieldActionPerformed(null);
    }//GEN-LAST:event_decimalTextFieldFocusLost

    private void complementHexTextFieldgenericCopyMenu(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_complementHexTextFieldgenericCopyMenu
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_complementHexTextFieldgenericCopyMenu

    private void complementHexTextFieldgenericCopyMenu1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_complementHexTextFieldgenericCopyMenu1
        if (evt.isPopupTrigger())
        copyPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_complementHexTextFieldgenericCopyMenu1

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField complementDecimalTextField;
    private javax.swing.JTextField complementHexTextField;
    private org.harctoolbox.guicomponents.CopyPastePopupMenu copyPastePopupMenu;
    private org.harctoolbox.guicomponents.CopyPastePopupMenu copyPopupMenu;
    private javax.swing.JTextField decimalTextField;
    private javax.swing.JTextField hexTextField;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField reverseComplementDecimalTextField;
    private javax.swing.JTextField reverseComplementHexTextField;
    private javax.swing.JTextField reverseDecimalTextField;
    private javax.swing.JTextField reverseHexTextField;
    private org.harctoolbox.guicomponents.StatusLine statusLine;
    // End of variables declaration//GEN-END:variables
}
